#include "QxWellInfoDataModel.hpp"

#include "QxWellLasFile.hpp"
#include "QxWellLogDataModel.hpp"

class QxWellInfoDataModel::QxWellInfoDataModelPrivate
{
public:

  QxWellInfoDataModelPrivate( QxWellInfoDataModel* me ) : m_self( me ) {
  }

  void init() {
    m_dataIO = new QxWellLasFile();
  }

  void parseFile( const QString& filename ) {
    if( QxWellLasFile* lasIO = dynamic_cast<QxWellLasFile*>( m_dataIO ) ) {
      lasIO->setFilename( filename );
      m_wellInfo = lasIO->wellInfoDefine();
      prepareWellLogs();
    }
  }

  void prepareWellLogs() {
    Q_FOREACH( const QxWellLogDefine& wellLogDefine, m_dataIO->wellLogDefines() ) {
      QxWellLogDataModel* wellLog = new QxWellLogDataModel;
      wellLog->setWellName( m_wellInfo.wellName );
      wellLog->setWellLogName( wellLogDefine.wellLogName );
      wellLog->setStartDepth( wellLogDefine.startDepth );
      wellLog->setStopDepth( wellLogDefine.stopDepth );
      wellLog->setStepDepth( wellLogDefine.stepDepth );
      wellLog->setNullValue( wellLogDefine.nullValue );
      wellLog->setData( m_dataIO->data( wellLogDefine.wellLogName ) );
      m_wellLogs << wellLog;
    }
  }

  QxWellInfoDataModel*         m_self;
                               
  QxWellDataIO*                m_dataIO;
  QxWellInfoDefine             m_wellInfo;
  QVector<QxWellLogDataModel*> m_wellLogs;
};

QxWellInfoDataModel::QxWellInfoDataModel() : _pd( new QxWellInfoDataModelPrivate( this ) )
{
  _pd->init();
}

QxWellInfoDataModel::QxWellInfoDataModel( const QString& filename ) : _pd( new QxWellInfoDataModelPrivate( this ) )
{
  _pd->init();
  _pd->parseFile( filename );
}

QxWellInfoDataModel::~QxWellInfoDataModel()
{
}

QxWellDataIO* QxWellInfoDataModel::dataIO()
{
  return _pd->m_dataIO;
}

void QxWellInfoDataModel::setDataIO( QxWellDataIO* dataIO )
{
  _pd->m_dataIO = dataIO;
}

const QString& QxWellInfoDataModel::workspaceName() const
{
  return _pd->m_wellInfo.workspaceName;
}

void QxWellInfoDataModel::setWorkspaceName( const QString& workspaceName )
{
  _pd->m_wellInfo.workspaceName = workspaceName;
}

const QString& QxWellInfoDataModel::wellName() const
{
  return _pd->m_wellInfo.wellName;
}

void QxWellInfoDataModel::setWellName( const QString& wellName )
{
  _pd->m_wellInfo.wellName = wellName;
}

const QPointF& QxWellInfoDataModel::location() const
{
  return _pd->m_wellInfo.location;
}

void QxWellInfoDataModel::setLocation( const QPointF& localtion )
{
  _pd->m_wellInfo.location = localtion;
}

float QxWellInfoDataModel::startDepth() const
{
  return _pd->m_wellInfo.startDepth;
}

void QxWellInfoDataModel::setStartDepth( float startDepth )
{
  _pd->m_wellInfo.startDepth = startDepth;
}

float QxWellInfoDataModel::stopDepth() const
{
  return _pd->m_wellInfo.stopDepth;
}

void QxWellInfoDataModel::setStopDepth( float stopDepth )
{
  _pd->m_wellInfo.stopDepth = stopDepth;
}

float QxWellInfoDataModel::stepDepth() const
{
  return _pd->m_wellInfo.stepDepth;
}

void QxWellInfoDataModel::setStepDepth( float stepDepth )
{
  _pd->m_wellInfo.stepDepth = stepDepth;
}

float QxWellInfoDataModel::nullValue() const
{
  return _pd->m_wellInfo.nullValue;
}

void QxWellInfoDataModel::setNullValue( float nullValue )
{
  _pd->m_wellInfo.nullValue = nullValue;
}

const QVector<QxWellLogDataModel*>& QxWellInfoDataModel::wellLogs() const
{
  return _pd->m_wellLogs;
}

void QxWellInfoDataModel::setWellLogs( const QVector<QxWellLogDataModel*>& wellLogs )
{
  _pd->m_wellLogs = wellLogs;
}
